﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Drawing.Imaging;

namespace Core
{
    public static class BarCode
    {
        public static Image CreateBarCode(string productId, string title, int? price, int? listedPrice,ref string code, string os)
        {
            code = FormatBarCode(productId.ToString());
            Ean13 ean13 = new Ean13(code, title, price, listedPrice, os);
            DateTime today = DateTime.Now;
            Image image = ean13.Paint();
            return image;
        }

        private static string FormatBarCode(string code)
        {
            var length = 12 - code.Length;
            if (length > 0)
            {
                for (int i = 0; i < length; i++)
                {
                    code = "0" + code;
                }
            }
            //Add checksum number
            var checkSum = Ean13.CalculateChecksum(code);
            code = code + checkSum.ToString();
            return code;
        }
    }
}
